select case when grouping(groupuid) = 1 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 1 then cast(user_name(groupuid) as varchar(20)) when grouping(groupuid) = 0 and grouping(memberuid) = 0 then '' end as role, case when grouping(groupuid) = 1 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 1 then '' when grouping(groupuid) = 0 and grouping(memberuid) = 0 then cast(user_name(memberuid) as varchar(30)) end as members from sysmembers group by groupuid, memberuid with rollup order by cast(user_name(groupuid) as varchar(20)), cast(user_name(memberuid) as varchar(30))